package com.zqh.messagemq.controller;

import com.zqh.messagemq.service.RabbitMqPublisher;
import com.zqh.myfmmall.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-03-01 14:57
 */
@RestController
@RequestMapping("messageMq")
@Slf4j
public class MessageMqController{
    @Resource
    private RabbitMqPublisher rabbitMqPublisher;

    @PostMapping("delayedMessage")
    public Result delayedMessage(@RequestParam("message") String message,
                                 @RequestParam(value = "ttl", required = false) Integer ttl) {

        if (ttl != null) {
            rabbitMqPublisher.publishDelayedMessage(message, ttl);
        }
        else {
            rabbitMqPublisher.publishDelayedMessage(message);
        }
        return Result.success();
    }
}
